package com.kaoker.system.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kaoker.system.dao.ISectionDao;
import com.kaoker.system.entity.Section;

public class SectionService {
	private Logger log = LoggerFactory.getLogger(SectionService.class);
	
	private ISectionDao dao;

	public SectionService() {

	}

	public ISectionDao getDao() {
		return dao;
	}

	public void setDao(ISectionDao dao) {
		this.dao = dao;
	}

	public void addSection(Section section) {
		dao.saveSection(section);
	}

	public void deleteSection(Section section) {
		dao.deleteSection(section);
	}

	public void deleteSection(Long sectionId) {
		dao.deleteSection(sectionId);
	}
	/**
	 * delete the current section, and all the subsections.
	 * @param section  the current section object.
	 */
	public void deleteAllSection(Section section) {			
		List<Section> sections = dao.getSubSections(section);
		log.debug("sub section size:" + sections.size());
		
		dao.deleteAllSection(sections);
		dao.deleteSection(section);
	}
	
	public void deleteAllSection(Long sectionId) {
		Section section = dao.getSection(sectionId);
		log.debug("delete All sections:" + section.getId() + "/" + section.getName());
		this.deleteAllSection(section);		
	}

	public List<Section> getSubSections(long sectionId) {
		Section parentSection = dao.getSection(sectionId);
        return dao.getSubSections(parentSection);
	}

	public List<Section> getSubSections(Section parentSection) {
		return dao.getSubSections(parentSection);
	}
	
	public Section getSectionById(Long sectionId) {
		return dao.getSection(sectionId);
	}
}
